﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Custom;

namespace MBilbaoMobilePro
{
    public partial class frmTarifas : Form
    {
        public frmTarifas()
        {
            InitializeComponent();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        string _tarifas;

        public void ShowDetail(string tarifas)
        {
            _tarifas = tarifas;

            this.ShowDialog();
        }

        private void cmbTipo_SelectedIndexChanged(object sender, EventArgs e)
        {
            billete billete = (billete)cmbTipo.SelectedItem;
            txtDescripcion.Text = billete.Descripcion;
            lbl1zona.Text = billete.Zona1;
            lbl2zonas.Text = billete.Zona2;
            lbl3zonas.Text = billete.Zona3;
        }

        private void frmTarifas_Load(object sender, EventArgs e)
        {
            this.Show();

            helper.FormDisable(this, "Cargando tarifas...");
            XmlDocument doc = helper.XmlGetDocumentFromSource(_tarifas);

            billete nuevoBillete;

            foreach (XmlNode billete in doc.SelectNodes("//billete"))
            {
                nuevoBillete = new billete();
                nuevoBillete.Nombre = billete.Attributes["nombre"].Value;
                nuevoBillete.Descripcion = billete.SelectSingleNode("descripcion").InnerText;
                nuevoBillete.Zona1 = billete.SelectSingleNode(".//zona1").InnerText;
                nuevoBillete.Zona2 = billete.SelectSingleNode(".//zona2").InnerText;
                nuevoBillete.Zona3 = billete.SelectSingleNode(".//zona3").InnerText;

                cmbTipo.Items.Add(nuevoBillete);
            }

            helper.FormEnable(this);

            if (cmbTipo.Items.Count > 0)
            {
                cmbTipo.SelectedIndex = 0;
            }

        }
    }
}